package com.tentact.servlets;

import com.mysql.cj.Session;
import com.tentact.dao.Admindao;
import com.tentact.service.AdminService;
import com.tentact.vo.Employee;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UpdateUserpwdServlet", value = "/UpdateUserpwdServlet")
public class UpdateUserpwdServlet extends HttpServlet {
    AdminService service = new AdminService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String userpwd = request.getParameter("userpwd");
        String newuserpwd = request.getParameter("newuserpwd");
        String newuserpwds = request.getParameter("newuserpwds");
        //获取会话
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        if (service.updateByEmployees(newuserpwd, username, userpwd) == 1) {
            Employee employee = new Employee(username,newuserpwd);
            service.selectByEmployees(employee);
            //将密码存入会话属性里
            session.setAttribute("userpwd", newuserpwd);

            request.getRequestDispatcher("SelectByNameMeetingServlet").forward(request, response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
